package com.zbl.zblproject.core.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zbl.zblproject.core.entity.Region;
import com.zbl.zblproject.core.entity.Result;
import com.zbl.zblproject.core.entity.UserAddress;
import com.zbl.zblproject.core.mapper.RegionMapper;
import com.zbl.zblproject.core.mapper.UserAddressMapper;
import com.zbl.zblproject.core.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author youlanqiang
 * @version 1.0
 * @date 2018/10/17
 *
 */
@RestController
@RequestMapping("/user-address")
@Api(tags={"用户地址接口"})
public class AddressController {

    @Autowired
    private UserAddressMapper userAddressMapper;

    @Autowired
    private RegionMapper regionMapper;

    @GetMapping("/{id}")
    @ApiOperation("获取客户地址")
    public Result userAddress(@ApiParam("用户ID") @PathVariable Integer id){
        QueryWrapper<UserAddress> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id", id);
        return ResultUtil.success("成功!", userAddressMapper.selectList(wrapper));
    }

    @GetMapping("/region/{parent}")
    @ApiOperation("获取父级下的地址")
    public Result getRegionByParent(@ApiParam("父级ID") @PathVariable int parent ){
        QueryWrapper<Region> wrapper = new QueryWrapper<>();
        wrapper.eq("parent_id", parent);
        return ResultUtil.success("成功!", regionMapper.selectList(wrapper));
    }


}
